const http  = require('http');

// 创建http服务器
http.createServer((req,res)=>{
  res.writeHead(200,{'Content-Type':'text/plain'});// 状态码,请求头
  res.end('hello world');// 设置响应
}).listen(1334,'127.0.0.1')


// 客户端
let options  = {
  hostname:'127.0.0.1',
  port:1334,
  path:'/',
  method:'GET'
}

let req = http.request(options,res=>{
  console.log('status:',res.statusCode);
  console.log('headers:',JSON.stringify(res.headers));
  res.setEncoding('utf-8');
  res.on('data',chunk=>{
    console.log(chunk);
  })
})
req.end()